package com.sun.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sun.entity.Product;
import com.sun.mapper.ProductMapper;
import com.sun.service.IProductService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author SunRui
 * @since 2024-12-10
 */
@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements IProductService {

    @Autowired
    ProductMapper productMapper;

    @Override
    public int insert(Product product) {
        return productMapper.insert(product);
    }

    @Override
    public int update(Product product) {
        return productMapper.updateById(product);
    }

    @Override
    public int delete(int id) {
        QueryWrapper<Product>  queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id",id);
        return productMapper.delete(queryWrapper);
    }


    @Override
    public List<Product> selectAll() {
        return productMapper.selectList(null);
    }

    @Override
    public Product selectById(Integer id) {
        return productMapper.selectById(id);
    }

    @Override
    public IPage<Product> selectPage(Integer page, Integer size) {
        Page pages = new Page<>(page,size);
        return productMapper.selectPage(pages);
    }

}
